package com.help.help.controller;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.excel.EasyExcel;
import com.help.help.entity.UserEntity;
import com.help.help.service.UserService;
import com.help.help.util.ExceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.help.help.entity.WithdrawEntity;
import com.help.help.service.WithdrawService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletResponse;


/**
 * 
 *
 * @author 小🌤
 * @email 1578442339@qq.com
 * @date 2021-01-07 15:41:11
 */
@RestController
@RequestMapping("/help/withdraw")
public class WithdrawController {
    @Autowired
    private WithdrawService withdrawService;
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = withdrawService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{uuid}")
    public R info(@PathVariable("uuid") String uuid){
		WithdrawEntity withdraw = withdrawService.getById(uuid);

        return R.ok().put("withdraw", withdraw);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody WithdrawEntity withdraw){
		withdrawService.save(withdraw);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody WithdrawEntity withdraw){
		withdrawService.updateById(withdraw);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] uuids){
		withdrawService.removeByIds(Arrays.asList(uuids));

        return R.ok();
    }

    /**
     * 导出
     * @param response
     * @param ids
     * @throws IOException
     */
    @RequestMapping("/updaloa")
    public void   upload(HttpServletResponse response, String[] ids) throws IOException {
        List<WithdrawEntity> list = withdrawService.listByIds(Arrays.asList(ids));
        for (WithdrawEntity withdrawEntity : list) {
             withdrawEntity.setStatusLong(withdrawEntity.getStatus()==0?"等待处理":"提现成功");
           withdrawEntity.setZfb(userService.getById(withdrawEntity.getUserId()).getZfb());
        }
        ExceUtil.out("提现信息导出", response);
        EasyExcel.write(response.getOutputStream(), WithdrawEntity.class).sheet("提现信息导出信息").doWrite(list);
    }

}
